from django.contrib import admin
from booktest.models import BookInfo, HeroInfo
from django.contrib.admin import TabularInline, StackedInline

# Register your models here.




# 定义管理类需要继承自admin.ModelAdmin类

class HeroInfoInline(StackedInline):
    model = HeroInfo  # 指定关联展示那个模型数据
    extra = 1   # 额外的编辑框



class BookInfoAdmin(admin.ModelAdmin):
    """书籍模型管理"""

    #  设置每页显示数据条数
    list_per_page = 2
    #设置操作选项
    actions_on_bottom = True
    actions_on_top = False

    # 列表界面显示那些列/字段
    # list_display = ('模型属性', '模型中的方法名')/[]  '1991-11-11'

    list_display = ['id', 'btitle', 'bpub_date', 'bread', 'bcomment','pub_data_format']

    """以下代码是调整编辑页面"""
    # fields = ['btitle', 'bpub_date', 'is_delete']
    # 编辑页面可以进行编辑字段,默认模型中的所有字段都可编辑

    fieldsets = [
        ['基础组', {'fields': ['btitle', 'bpub_date', 'image']}],
        ['高级组', {'fields': ['bread', 'bcomment', 'is_delete'],
                 'classes': ['collapse']
                 }]
    ]

    # 下面这个属性只能用在一的那方
    inlines = [HeroInfoInline]  # 编辑页面关联展示编辑


@admin.register(HeroInfo)
class HeroInfoAdmin(admin.ModelAdmin):
    """英雄模型管理类"""
    list_per_page = 5
    actions_on_bottom = True
    actions_on_top = False
    list_display = ['id', 'hname', 'hbook', 'hgender', 'hcomment', 'read']

    #右侧过滤器
    list_filter = ['hbook', 'hgender']
    # 顶部搜索框
    search_fields = ['hname', 'hcomment']


admin.site.register(BookInfo, BookInfoAdmin)

# admin.site.register(HeroInfo)

admin.site.site_header = '百川书城'
admin.site.site_title = '百川书城MIS'
admin.site.index_title = '欢迎使用百川书城MIS'